/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wso.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import wso.dto.WsoProductType;
import wso.global.BaseDao;

/**
 *
 * @author Violet_Ink
 */
public class ProductTypeDaoImpl extends BaseDao implements ProductTypeDao {

    public void saveOrUpdateProductType(WsoProductType producttype) {
        saveOrUpdate(producttype);
    }

    public void deleteProductType(String producttypeid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("update WsoProductType protype set protype.isdeleted = true where protype.producttypeid = :producttypeid");
        query = session.createQuery(str.toString());
        query.setString("producttypeid", producttypeid);

        query.executeUpdate();
    }

    public WsoProductType[] getAllProductType() {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();
        str.append("from WsoProductType protype where protype.isdeleted = false");
        query = session.createQuery(str.toString());
        List userList = query.list();
        WsoProductType[] result = new WsoProductType[userList.size()];
        userList.toArray(result);

        return result;
    }

    public WsoProductType getProductType(String producttypeid) {
        Session session = getSession();
        Query query = null;
        StringBuilder str = new StringBuilder();

        str.append("from WsoProductType protype where protype.producttypeid = :producttypeid and protype.isdeleted = false");
        query = session.createQuery(str.toString());
        query.setString("producttypeid", producttypeid);

        return (WsoProductType) query.uniqueResult();
    }

}
